﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using VDataAdapter.BlockingQueue;

namespace VDataAdapter.Communication
{
    /// <summary>
    /// this class allow the control of FLag Checker
    /// so that we can move to Transaction Stage
    /// instead of must going through Begin End Stage
    /// </summary>
    class VDataCommunicatorMock : VDataCommunicator
    {
        public VDataCommunicatorMock(DataSource dataSource, CommunicationDataQueue queue) : base(dataSource, queue) { }

        /// <summary>
        /// send BEGIN # END then clear queue to move to transaction stage
        /// from now queue is empty, and flagChecker will not raise any exception
        /// </summary>
        public void MoveToSendingTransactionStage()
        {
            SendFlag(MessageFlagSequeue.BEGIN);
            SendFlag(MessageFlagSequeue.END);
            _queue.clear();  
        }

        /// <summary>
        /// send BEGIN # END # END_RECOVERY (3 flags) then clear queue to move to transaction stage
        /// from now queue is empty, and flagChecker will not raise any exception
        /// </summary>
        public void MoveToFreeSendingStage()
        {
            SendFlag(MessageFlagSequeue.BEGIN);
            SendFlag(MessageFlagSequeue.END);
            SendFlag(MessageFlagSequeue.END_RECOVERY);
            _queue.clear();
        }
    }
}
